class BackStages::Show::ReshipsController < ApplicationController
  def index
    @document_type_name = params[:document_type_name]
    @sreach_name = params[:name]
    @sreach_time = params[:time_ago]

    if params[:document_type_name].blank?
      @document_id = "%"
    else
      @document_id = DocumetType.find_by_name(params[:document_type_name]).id
    end

    if params[:name].blank?
      @reship_name = "%"
    else
      @reship_name = params[:name]
    end

    if params[:time_ago] == "今天"
      @time_ago = 1.days.ago
    else if params[:time_ago] == "一周内"
        @time_ago = 7.days.ago
      else
        @time_ago = 30.days.ago
      end
    end

    @all_reships = Reship.all :conditions => ["documet_type_id like ? and title like ? and created_at >= ? ",
        @document_id,
        "%" + @reship_name + "%",
        @time_ago
      ]

    @reships = Reship.paginate(
      :conditions => ["documet_type_id like ? and title like ? and created_at >= ? ",
        @document_id,
        "%" + @reship_name + "%",
        @time_ago
      ],
      :page => params[:page_number],
      :per_page => 5,
      :order => "created_at desc")
  end

  def show
    if params[:document_type_name].blank?
      @document_id = "%"
    else
      @document_id = DocumetType.find_by_name(params[:document_type_name]).id
    end

    @all_reships = Reship.all :conditions => ["documet_type_id like ?",
        @document_id
      ]

    @reships = Reship.paginate(
      :conditions => ["documet_type_id like ?",
        @document_id
      ],
      :page => params[:page_number],
      :per_page => 5,
      :order => "created_at desc")
  end

  def destroy
    @document_type_name = params[:document_type_name]
    @sreach_name = params[:name]
    @sreach_time = params[:time_ago]

    @reship = Reship.find params[:id]
    @reship.destroy

    if params[:document_type_name].blank?
      @document_id = "%"
    else
      @document_id = DocumetType.find_by_name(params[:document_type_name]).id
    end

    if params[:name].blank?
      @reship_name = "%"
    else
      @reship_name = params[:name]
    end

    if params[:time_ago] == "今天"
      @time_ago = 1.days.ago
    else if params[:time_ago] == "一周内"
        @time_ago = 7.days.ago
      else
        @time_ago = 30.days.ago
      end
    end

    @all_reships = Reship.all :conditions => ["documet_type_id like ? and title like ? and created_at >= ? ",
        @document_id,
        "%" + @reship_name + "%",
        @time_ago
      ]

    @reships = Reship.paginate(
      :conditions => ["documet_type_id like ? and title like ? and created_at >= ? ",
        @document_id,
        "%" + @reship_name + "%",
        @time_ago
      ],
      :page => params[:page_number],
      :per_page => 5,
      :order => "created_at desc")
  end

  def authorize

  end
end
